package cn.xiu.drugstore.dao.impl;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import cn.xiu.drugstore.dao.BuyDrugDao;
import cn.xiu.drugstore.pojo.BuyDrug;
import cn.xiu.drugstore.util.BaseDao;
/**
 * 药品购买详情实现类
 * @author 李魏魏
 *
 */
public class BuyDrugDaoImpl extends BaseDao implements BuyDrugDao {



	@Override
	public List<BuyDrug> cheackDrug() throws Exception {
		ArrayList<BuyDrug> list=new ArrayList<BuyDrug>();
		String sql="SELECT Dillid,Drugid,DrugCount FROM buydrug";
		ResultSet rs = super.executeQuery(sql, null);
		if(rs.next()&&rs!=null){
			while(rs.next()){
				BuyDrug bd=new BuyDrug();
				bd.setDillId(rs.getInt("Dillid"));
				bd.setDrugCount(rs.getInt("DrugCount"));
				bd.setDrugId(rs.getInt("Drugid"));
				list.add(bd);
				
			}
			
		}
		super.closeResource(rs);
		return list;
	}

	@Override
	public int saveDrug(BuyDrug bd) throws Exception {
		String sql="INSERT INTO buydrug(Dillid,Drugid,DrugCount)VALUE(?,?,?)";
		Object[] params={bd.getDillId(),bd.getDrugId(),bd.getDrugCount()};
		int result = super.executeUpdate(sql, params);
		super.closeResource(null);
		return result;
	}

}
